home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SATAN11.ZIP / RECONFIG < prev    next >
Text File  |  1995-04-09  |  5KB  |  168 lines

  1. #!/bin/sh -- need to mention perl here to avoid recursion
  2. 'true' || eval 'exec perl -S $0 $argv:q';
  3. eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
  4. & eval 'exec /usr/local/bin/perl -S $0 $argv:q'
  5.     if 0;
  6.  
  7. #
  8. # version 1, Sun Mar 26 18:31:28 1995, last mod by zen
  9. #
  10.  
  11. #  Usage: [perl] reconfig [file]
  12. #
  13. #   This replaces the program paths (e.g. /bin/awk) in SATAN with an
  14. # alternate path that is found in the file "file.paths".  It also finds
  15. # perl5 (or at least tries!) and changes the path in all the stand-alone
  16. # perl programs.
  17. #
  18.  
  19. # all the HTML browsers we know about, IN ORDER OF PREFERENCE!
  20. @all_www= ("netscape", "Mosaic", "xmosaic", "lynx");
  21.  
  22. #
  23. #  Potential directories to find commands; first, find the user's path...
  24. $PATH = $ENV{"PATH"};
  25.  
  26. # additional dirs; *COLON* separated!
  27. $other_dirs="/usr/ccs/bin:/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/ucb/bin:/usr/sbin:/usr/etc:/usr/local/bin:/usr/bin/X11:/usr/X11/bin:/usr/openwin/bin";
  28.  
  29. #
  30. # split into a more reasonable format. Personal aliases come last.
  31. @all_dirs = split(/:/, $other_dirs . ":" . $PATH);
  32.  
  33. #
  34. #  Target shell scripts in question:
  35. @shell_scripts=("config/paths.pl", "config/paths.sh");
  36. @perl5_src = <bin/get_targets bin/faux_fping satan bin/*.satan perl/html.pl>;
  37.  
  38. #
  39. #  Target shell commands in question
  40. @all_commands=("cc", "cat", "chmod", "cmp", "comm", "cp", "date", "diff",
  41.     "egrep", "expr", "find", "grep", "ls", "mail", "mkdir", "mv", "rm",
  42.     "sed", "sh", "sort", "tftp", "touch", "uniq", "uudecode", "ypcat",
  43.     "strings", "finger", "ftp", "rpcinfo", "rusers", "showmount", "ping",
  44.     "ypwhich", "nslookup", "xhost", "su", "awk", "sed", "test", "whoami", 
  45.     "basename", "echo", "file");
  46.  
  47. print "checking to make sure all the target(s) are here...\n";
  48.  
  49. for (@shell_scripts) {
  50.     die "ERROR -- $_ not found!\n" unless -f $_;
  51.     }
  52.  
  53. # find perl5!
  54. print "Ok, trying to find perl5 now... hang on a bit...\n";
  55. for $dir (@all_dirs) {
  56.     # first, find where it might be; oftentimes you'll see perl,
  57.     # perl4, perl5, etc. in the same dir
  58.     next if (! -d $dir);
  59.     while (<$dir/perl5* $dir/perl*>) {
  60.         if (-x $_) {
  61.             $perl_version=`($_ -v 2> /dev/null) |
  62.                 awk '/This is perl, version 5/ { print $NF }'`;
  63.             if ($perl_version) {
  64.                 $PERL=$_;
  65.                 $pflag="1";
  66.                 last;
  67.                 }
  68.             }
  69.             last if $pflag;
  70.         }
  71.     last if $pflag;
  72.     }
  73.  
  74. die "\nCan't find perl5!  Bailing out...\n" unless $PERL;
  75. print "\nPerl5 is in $PERL\n";
  76.  
  77. for (@perl5_src) { $perl5_src .= "$_ "; }
  78. print "\nchanging the source in: $perl5_src\n";
  79. system "$PERL -pi -e \"s@^#!.*/perl.*@#!$PERL@;\" $perl5_src";
  80.  
  81. # make sure things are executable...
  82. system("chmod u+x $perl5_src");
  83.  
  84. # find the most preferred www viewer first.
  85. for $www (@all_www) {
  86.     for $dir (@all_dirs) {
  87.         if (!$MOSAIC) {
  88.             if (-x "$dir/$www") {
  89.                 $MOSAIC="$dir/$www";
  90.                 next;
  91.                 }
  92.             }
  93.         }
  94.     }
  95. if ($MOSAIC) {
  96.     print "\nHTML/WWW Browser is $MOSAIC\n";
  97.     $upper{"MOSAIC"} = $MOSAIC;
  98.     }
  99. else { print "Cannot find a web browser!  SATAN cannot be run except in CLI"; }
  100.  
  101. print "\nSo far so good...\nLooking for all the commands now...\n";
  102.  
  103. for $command (@all_commands) {
  104.     $found="";
  105.     for $dir (@all_dirs) {
  106.         # special case rsh/remsh; if we can find remsh, ignore rsh
  107.         if ($command eq "rsh") {
  108.             # print "looking for rsh/remsh ($dir/$command)\n";
  109.             if (-f "$dir/remsh") {
  110.                 # this converts to upper case
  111.                 ($upper = $command) =~ y/[a-z]/[A-Z]/;
  112.                 $found="true";
  113.                 $upper{$upper} = "$dir/remsh";
  114.                 print "found $dir/remsh; using this instead of rsh\n";
  115.                 last;
  116.                 }
  117.             }
  118.  
  119.         # if find the command in one of the directories, print string
  120.         if (-f "$dir/$command") {
  121.             # this converts to upper case
  122.             ($upper = $command) =~ y/[a-z]/[A-Z]/;
  123.             $found="true";
  124.             $upper{$upper} = "$dir/$command";
  125.             # print "found ($upper) $dir/$command\n";
  126.  
  127.             # if it's rsh we're examining, keep looking; else quit
  128.             last unless $command eq "rsh";
  129.             }
  130.         }
  131.     print "\nAEEEIIII...!!!  can't find $command\n\n" unless $found;
  132.     }
  133.  
  134. print "\nOk, now doing substitutions on the shell scripts...\n";
  135. for $shell (@shell_scripts) {
  136.      print "Changing paths in $shell...\n";
  137.     die "Can't open $shell\n" unless open(SCRIPT, $shell);
  138.     rename($shell, $shell . '.old');
  139.     die "Can't open $shell\n" unless open(OUT, ">$shell");
  140.  
  141.     #
  142.     #  Open up the script, search for lines beginning with
  143.     # stuff like "TEST", "AWK", etc.  If the file ends in "pl",
  144.     # assume it's a perl script and change it accordingly
  145.     while (<SCRIPT>) {
  146.         $found = 0;
  147.         for $command (keys %upper) {
  148.             if(/^\$?$command=/) {
  149.                 # shell script
  150.                 if ($shell !~ /.pl$/) {
  151.                     print OUT "$command=$upper{$command}\n";
  152.                     }
  153.                 # perl script
  154.                 else {
  155.                     print OUT "\$" . "$command=\"$upper{$command}\";\n";
  156.                     }
  157.                 $found = 1;
  158.                 }
  159.             }
  160.         print OUT $_ if !$found;
  161.         }
  162.     close(SCRIPT);
  163.     close(OUT);
  164.     }
  165.  
  166. # done...
  167.  
  168.